home *** CD-ROM | disk | FTP | other *** search
- /*
- * A more or less BSD compatable socket library for MacTCP
- *
- * Summer 1989, Tom Milligan, University of Toronto Computing Services
- */
-
-
- #define NUM_SOCKETS 32 /* Number of sockets. Should never exceed 32 */
-
- #define STREAM_BUFFER_SIZE 20000 /* memory for MacTCP streams */
-
- #define UDP_MAX_MSG 65507 /* MacTCP max legal udp message */
- #define TCP_MAX_MSG 65535 /* MacTCP max legal tcp message */
-
- #define TCP_MAX_WRITES 16 /* socket (not TCP) max writes in progress */
-
- /*
- * In use and shutdown status.
- */
- #define SOCK_STATUS_USED 0x1 /* Unused socket table entry */
- #define SOCK_STATUS_NOREAD 0x2 /* No more reading allowed from socket */
- #define SOCK_STATUS_NOWRITE 0x4 /* No more writing allowed to socket */
-
- /*
- * Socket connection states.
- */
- #define SOCK_STATE_NO_STREAM 0 /* socket doesn't have a MAcTCP stream yet */
- #define SOCK_STATE_UNCONNECTED 1 /* Socket is unconnected. */
- #define SOCK_STATE_LISTENING 2 /* Socket is listening for connection. */
- #define SOCK_STATE_LIS_CON 3 /* Socket is in transition from listen to connected. */
- #define SOCK_STATE_CONNECTING 4 /* Socket is initiating a connection. */
- #define SOCK_STATE_CONNECTED 5 /* Socket is connected. */
-
- typedef union mactcp_pb
- {
- TCPiopb tcp;
- UDPiopb udp;
- struct IPParamBlock ip;
- } mactcp_pb;
-
- typedef struct async_pb
- {
- mactcp_pb pb; /* MacTCP parameter block */
- struct SocketRecord *sp; /* ptr back to socket for completion routines */
- } async_pb;
-
- typedef struct write_pb
- {
- mactcp_pb pb; /* MacTCP parameter block */
- struct SocketRecord *sp; /* ptr back to socket for completion routines */
- wdsEntry wds[2]; /* single entry MacTCP wds structure */
- } write_pb;
-
- typedef struct SocketRecord
- {
- mactcp_pb pb; /* parameter block for synchronous operations */
- async_pb apb; /* parameter block for read, listen and connect */
- write_pb wpb[TCP_MAX_WRITES];/* parameter blocks for write */
- short nextwpb; /* index of next wpb to use */
- byte status; /* Is file descriptor in use */
- int fd; /* fd number */
- struct sockaddr_in sa; /* My address. */
- struct sockaddr_in peer; /* Her address. */
- short protocol; /* Protocol (e.g. TCP, UDP) */
- Boolean nonblocking;/* socket set for non-blocking I/O. */
- byte sstate; /* socket's connection state. */
- unsigned long dataavail; /* Amount of data available on connection. */
- int asyncerr; /* Last async error to arrive. zero if none. */
- /* stdio stuff */
- char *outbuf; /* Ptr to array to buffer output */
- int outbufcount;/* # of characters in outbuf */
- Ptr outbufptr; /* Pointer into outbuf */
- char *inbuf; /* Ptr to array to buffer input */
- int inbufcount; /* # of characters in inbuf */
- Ptr inbufptr; /* Pointer into inbuf */
- Boolean ioerr; /* Holds error status for stdio calls */
- Boolean ioeof; /* EOF was detected on stream */
- } SocketRecord, *SocketPtr;
-
-
- /*-------------------------------------------------------------------------*/
- #define sock_set(f,s) f |= (1 << s)
- #define sock_is_set(f,s) (((f) & (1 << s)) != 0)
-
- #define SOCK_MIN_PTR (Ptr)0x1400 /* Minimum reasonable pointer */
- #define goodptr(p) ((p) > SOCK_MIN_PTR)
- #define is_used(p) (goodptr(p) && (p)->status & SOCK_STATUS_USED)
- #define is_stdio(p) (is_used(p) && (p)->inbuf != NULL)
- #define sock_good_fd(s) ((0 <= s && s < NUM_SOCKETS) && is_used (&sockets[s]))
- #define sock_nowrite(p) ((p)->status & SOCK_STATUS_NOWRITE)
- #define sock_noread(p) ((p)->status & SOCK_STATUS_NOREAD)
-
- #define TVTOTICK(tvsec,tvusec) ( ((tvsec)*60) + ((tvusec)/16666) )
- #define min(a,b) ( (a) < (b) ? (a) : (b))
- #define max(a,b) ( (a) > (b) ? (a) : (b))
-
-
- /*
- * Global storage
- */
- #ifdef SOCKET
- SocketPtr sockets = NULL; /* The socket table. */
- ProcPtr spinroutine = NULL; /* The spin routine. */
- #else
- extern SocketPtr sockets;
- extern ProcPtr spinroutine;
- #endif
-